#ifndef __HZ_WINDOW_H__
#define __HZ_WINDOW_H__

#include <windows.h>
#include <string>
#include "hzProcess.h"
#include "hzMath.h"
#include "owner_ptr.hpp"

using namespace std;


namespace hz {

	namespace core {
		const int		DEF_X			= CW_USEDEFAULT;
		const int		DEF_Y			= CW_USEDEFAULT;
		const int		DEF_WIDTH		= 800;
		const int		DEF_HEIGHT		= 600;
		const DWORD		DEF_STYLE		= WS_OVERLAPPEDWINDOW;
		const UINT		DEF_WND_STYLE	= CS_HREDRAW | CS_VREDRAW;
		const int		DEF_MENU		= NULL;
		const HICON		DEF_ICON		= NULL;
		const HICON		DEF_ICON_SM		= NULL;
		const HCURSOR	DEF_CURSOR		= LoadCursor(NULL, IDC_ARROW);
		const HBRUSH	DEF_BACKGROUND	= (HBRUSH)(COLOR_WINDOW+1);


		class window : public owner_ptr<window> {
		public:
			enum type {
				CONSOLE,
				WINDOW, 
				DIALOG
			};

			struct attribute {
				type				Type;
				wstring				WindowName;
				wstring				_TitleBarName;
				math::vector2d		WindowPos;
				math::vector2d		WindowClientSize;
				bool				FullScreen;
				bool				Menu;
				bool				Minimized;
				bool				Focus;
			};



		private:
			HWND							_hWnd;
			attribute						_Attribute;			
			
			HMENU	_hMenu;
			DWORD	_WindowStyle;
			RECT	_WindowRect;

			void UpdateWindowPos(void);
			void UpdateWindowClientSize(void);

		public:
			window(void);
			~window(void);

			const HWND& GetHWND(void) const;
			const attribute& GetAttribute(void) const;

			bool Init(HINSTANCE hInst, wstring windowName, wstring title, 
					  const window* parents = NULL,	int x = DEF_X,							int y = DEF_Y, 
					  int width = DEF_WIDTH,		int height = DEF_HEIGHT,				bool fullscreen = false,
					  DWORD style = DEF_STYLE,		UINT wndStyle = DEF_WND_STYLE,			int menuResource = DEF_MENU, 
					  HICON icon = DEF_ICON,		HICON iconSm = DEF_ICON_SM,
					  HCURSOR cursor = DEF_CURSOR,	HBRUSH background = DEF_BACKGROUND);
			bool Init(const process& windowProcess,DWORD dialogResourceID, const window* parents = NULL);

			bool ChangeWindow(int x, int y, int width, int height);
			bool ChangeWindow(DWORD style);
			bool ChangeWindow(void);

			
			virtual bool CALLBACK CustomProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

		private:

			static LRESULT CALLBACK staticWinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
			static LRESULT CALLBACK staticDialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
		};	
	};
};

#endif